package tools.vetorial;

import java.awt.Color;

import core.DrawContext;
import core.Object2D;
import core.OurGraphics;
import core.Point3D;
import core.Poligon;
import core.VectorialObject;

public class VectorialRectTool extends PointSelectionTool {

	private VectorialRectProxy mProxy = new VectorialRectProxy();

	private Poligon mObject;
	
	private Point3D mProxyPt = new Point3D(0, 0);
	
	private Color mHachuraColor = Color.black;
	
	private int mHachuraSize = 10;
	
	@Override
	public void addPoint(int x, int y, int order, DrawContext ctx) {
		
		if(order%2 == 0) {
			mObject.addVertice(new Point3D(x, y));
		}
		else {
			Point3D firstPt = mObject.getVertice(0);
			
			mObject.addVertice(new Point3D(x, firstPt.getY()));
			
			mObject.addVertice(new Point3D(x, y));
			
			mObject.addVertice(new Point3D(firstPt.getX(), y));
			
			mObject.hachura(mHachuraColor, mHachuraSize);
			
			mObject.setmColor(this.getColor());
			
			pencilUp(ctx);
			pencilDown(ctx);
		}
		
	}

	@Override
	public Object2D getProxy() {
		return mProxy;
	}

	@Override
	public void pencilDown(DrawContext ctx) {
		mObject = new Poligon();
	}

	@Override
	public void pencilUp(DrawContext ctx) {
		if(mObject.getVerticeCount() == 4) {
			System.out.println("Adicionando rect");
			ctx.addObject2d(mObject);
			ctx.setChanged(true);
		}
		mObject = null;
	}

	@Override
	public void updateProxy(int x, int y, DrawContext ctx) {
		mProxyPt.setX(x);
		mProxyPt.setY(y);
	}
	
	private class VectorialRectProxy implements Object2D {
		
		@Override
		public void draw(OurGraphics g2) {
			
			if(mObject == null || mObject.getVerticeCount() == 0) {
				return;
			}
			
			Point3D pt1 = mObject.getVertice(0);
			
			g2.setColor(VectorialRectTool.this.getColor());
			
			g2.drawSquare(pt1, mProxyPt);
		}
		
	}

	public Color getHachuraColor() {
		return mHachuraColor;
	}

	public void setHachuraColor(Color mHachuraColor) {
		this.mHachuraColor = mHachuraColor;
	}

	public int getHachuraSize() {
		return mHachuraSize;
	}

	public void setHachuraSize(int mHachuraSize) {
		this.mHachuraSize = mHachuraSize;
	}

	@Override
	public void onSelection(VectorialObject vo) {
		// TODO Auto-generated method stub
		
	}

}
